package com.example.nfc.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.widget.LinearLayout;

import com.example.nfc.R;
import com.example.nfc.adapter.XjdkAdapter;
import com.example.nfc.base.BaseNfcActivity;
import com.example.nfc.server.network.http.HttpException;
import com.example.nfc.server.request.JeLoadRequest;
import com.example.nfc.server.response.JeLoadRespone;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 巡检打卡与盘点
 */
public class XjdkypdActivity extends BaseNfcActivity {

    private XjdkAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xjdkypd);
        ButterKnife.bind(this);
        adapter = new XjdkAdapter(mContext, new XjdkAdapter.ClickCallBack() {
            @Override
            public void open(int position) {

            }
        });
        lv.setLayoutManager(new LinearLayoutManager(mContext));
        lv.setHasFixedSize(true);
        lv.setAdapter(adapter);
        jeLoadRequest = new JeLoadRequest();
        jeLoadRequest.setFuncCode("INFO");
        jeLoadRequest.setFuncId("w7oYHEhqHv2ikgi30f2");
        jeLoadRequest.setColumnLazy("true");
        jeLoadRequest.setMark("false");
        jeLoadRequest.setPostil("");
        jeLoadRequest.setFuncEdit("false");
        jeLoadRequest.setCoverJquery("0");
        jeLoadRequest.setTableCode("INFO");
        jeLoadRequest.set_isFunc_("true");
        jeLoadRequest.setJ_query("%7B%22custom%22%3A%5B%5D%2C%22_custom_types%22%3A%5B%5D%7D");
        jeLoadRequest.setJ_order("%5B%5D");
        jeLoadRequest.setPage("1");
        jeLoadRequest.setStart("0");
        jeLoadRequest.setLimit("3000");
        request(GET_DATA);
    }

    @Bind(R.id.lv)
    RecyclerView lv;

    @Bind(R.id.leftBtn)
    LinearLayout leftBtn;
    @OnClick(R.id.leftBtn)
    public void leftBtnClick(){
        finish();
    }

    private static final int GET_DATA = 1010;
    private JeLoadRequest jeLoadRequest;
    @Override
    public Object doInBackground(int requestCode, String parameter) throws HttpException {
        switch (requestCode){
            case GET_DATA:
                return action.getDataRequest(jeLoadRequest);
        }
        return super.doInBackground(requestCode, parameter);
    }

    @Override
    public void onSuccess(int requestCode, Object result) {
        super.onSuccess(requestCode, result);
        switch (requestCode){
            case GET_DATA:
                JeLoadRespone respone = (JeLoadRespone)result;
                if("1000".equals(respone.getCode())){
                    adapter.update(respone.getRows());
                }else{
                    shortToast(respone.getMessage());
                }
                break;
        }
    }

    @Override
    public void onFailure(int requestCode, int state, Object result) {
        super.onFailure(requestCode, state, result);
    }
}